package com.mx.kn.cstf2.actions;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import kn.cstf2.assign.Shared.AssignShared;
import kn.cstf2.global.Utils.ConexionFtp;
import kn.cstf2.global.Utils.CstF2Exception;
import kn.cstf2.global.Utils.MyReportCreator;
import kn.cstf2.main.Server.MainServer;
import kn.cstf2.main.Shared.MainShared;
import kn.cstf2.transition.Bean.AsignIfownerStkBean;
import kn.cstf2.transition.Bean.JoinPersonTransitionBean;
import kn.cstf2.transition.Bean.Localidad;
import kn.cstf2.transition.Bean.PersonalBean;
import kn.cstf2.transition.Bean.TransitionBean;
import kn.cstf2.transition.Server.TransitionServer;
import kn.cstf2.transition.Shared.TransitionShared;
import kn.mx.cstf2.actions.CommonActions;


import com.mx.kn.cstf2.dto.HistoricoDto;
import com.mx.kn.cstf2.dto.UsuarioDto;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

import com.mx.kn.cstf2.actions.padre.Transition;
import com.mx.kn.cstf2.dts.FilesUploadDts;
import com.mx.kn.cstf2.dts.JoindocumenttransitionDts;
import com.mx.kn.cstf2.dts.PersonOptions;
import com.mx.kn.cstf2.service.MailService;
import com.mx.kn.cstf2.service.MainService;
import com.mx.kn.cstf2.service.TransitionService;
import com.mx.kn.cstf2.utils.AccionesHistorico;
import com.mx.kn.cstf2.utils.FormatFecha;
import com.mx.kn.cstf2.utils.MailSender2;
import com.mx.kn.cstf2.utils.TipoUsuarios;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Component("transitionAction")
@Scope(value="session")
public class TransitionAction extends ActionSupport implements
ServletRequestAware{
	private String result;
	private String statusselected;
    private String TRANSITION = "transition";
    private String PDF = "pdf";
    private String ZIP = "zip";
    private String ERROR_DOWN = "errorFileTransition";
    private String knkey;
    private TransitionBean transitionBeanM = new TransitionBean();
    private File archivo1, archivo2, archivo3, archivo4, archivo5, archivo6, archivo7, archivo8;
    private ArrayList<String> statusList = new ArrayList<String>();
    private ArrayList<String> personList = new ArrayList<String>();
    private ArrayList<PersonalBean> detallesPersonD;
    private ArrayList<PersonalBean> newArrayPerson;
    private Integer idDownloadFtp = 0;
    private String clientInfo;
    private String CorreoIfOwnerInfo = new String();
    

    public static final String ERROR_SESSION = "errorSession";
    public static final String ERROR_KNKEY = "errorKnkey";
    private int index = 0;
    private String status;
    private String auxStatus;
    private String datos = "";
    private String person = new String();
    private PersonalBean pb = new PersonalBean();
    private TransitionBean transitionBean = new TransitionBean();
    private UsuarioDto usuarioT = new UsuarioDto();
    private InputStream pdfInputStream;
    private Boolean box1;
    private Boolean box2;
    private Boolean box3;
    private Boolean box4;
    private Boolean box5;
    private Boolean box6;
    private Boolean box7;
    private Boolean box8;
    private Boolean box1aux;
    private Boolean box2aux;
    private Boolean box3aux;
    private Boolean box4aux;
    private Boolean box5aux;
    private Boolean box6aux;
    private Boolean box7aux;
    private Boolean box8aux;
    private Boolean valBranch;
    private String msjBranch ;
    private ArrayList<Boolean> voBos;
    private Integer documentId = 0;
    private Integer KNKEY;
    private ArrayList<Localidad> branch = new ArrayList<Localidad>();
    private String locality;
    private Boolean existe1;
    private Boolean existe2;
    private Boolean existe3;
    private Boolean existe4;
    private Boolean existe5;
    private Boolean existe6;
    private Boolean existe7;
    
    private Boolean enabledCheckCustomerProfile;
    private Boolean enabledCheckRFC;
    private Boolean enabledR1R2;
    private Boolean enabledSalesCall;
    private Boolean enabledCustomerQuotation;
    private Boolean enabledRateTracker;
    private Boolean enabledAconDebtorNumber;
    private Boolean checkCC;


    
    private List<PersonalBean> records = new ArrayList<PersonalBean>();
    private Transition transition;
    private Map<String, Object> sesion2;
    private Map<String, Object> sesion;
    private String id;
    private String value;
    private String lastDateStatusTransition;
    private String newCommnet;
    private String lastDateNewComment;
    private String lastDateUpdateRequeri;
    private String lastDateUpdateUploadFileRequeri;
    
    private String rateTrackerText;
    private String acondeborNumberText;
    private String rateTracker;
    private String aconDebtorNumber;
    
    private PersonalBean personalBean;
    private String idInsertPersonExist;
    
    private boolean errorEstatusUpdate;
    private String msgErrorEstatusUpdate;
    private List<PersonOptions> options;

    
    
    
    private File customerProfileFile;
	private File rfcFile;
	private File r1R2File;
	private File salesCallFile;
	private File customerQuotationFile;
	
	
	
	private String customerProfileFileFileName;
	private String rfcFileFileName;
	private String r1R2FileFileName;
	private String salesCallFileFileName;
	private String customerQuotationFileFileName;
	
	
	
	private String addNewPersonalBF;
	private String addNewPersonalName;
	private String addNePersonalEmal;
	private String addNewPersonalTelephone;
	
	private String customerProfileFileContentType;
	private String filePath;
	private HttpServletRequest servletRequest;
	
    //spring
    @Autowired TransitionService transitionService;
    @Autowired MainService mainService;
    @Autowired MailService mailService;

    

    

	@Override
    public String execute(){
		limpiar();
//        try {
            ActionContext contexto = ActionContext.getContext();
            sesion = contexto.getSession();
            sesion2 = contexto.getSession();
            this.setUsuarioT((UsuarioDto) sesion.get("usuarioSession"));
            
            switch (this.getUsuarioT().getTipo()) {
			case TipoUsuarios.USER_FS:
				transition = new TransitionFS();
				transition.setTransitionBeanM((TransitionBean) sesion2.get("Knkey"));
				transition.getTransitionBeanM().setTipoTransition(TipoUsuarios.USER_FS);
				if(!this.validaKnKey())
					  return ERROR_KNKEY;
				break;
				
			case TipoUsuarios.USER_FO:
				transition = new TransitionFO();
				transition.setTransitionBeanM((TransitionBean) sesion2.get("Knkey"));
				transition.getTransitionBeanM().setTipoTransition(TipoUsuarios.USER_FO);
				if(!this.validaKnKey())
					  return ERROR_KNKEY;
				break;

			case TipoUsuarios.USER_FA:
				transition = new TransitionFA();
				transition.setTransitionBeanM((TransitionBean) sesion2.get("Knkey"));
				transition.getTransitionBeanM().setTipoTransition(TipoUsuarios.USER_FA);
				if(!this.validaKnKey())
					  return ERROR_KNKEY;
				break;
			default:
				break;
			}
            
           
            statusList = CommonActions.getStatusList(this.statusselected);
            try {
            	transition.setTransitionBeanM(transitionService.getTransitionBeanIdKnkey(transition.getTransitionBeanM()));
    			transition.getTransitionBeanM().setTime(new Date());
    			sesion2.put("Knkey", transition.getTransitionBeanM());
				transition.setT_clientesDataFromStkBean(transitionService.getDataFromSTK(transition.getTransitionBeanM()));
				transition.setAsignIfownerStkBean(transitionService.getIfOwnerFromSTK(transition.getTransitionBeanM())); 
				transition.setDetallesPersonD(transitionService.getDataPersonalByIdPersonal(transition.getTransitionBeanM().getId()));
	            sesion2.put("personalD", (List<PersonalBean>)transition.getDetallesPersonD());
	            transitionBean = transitionService.getLastDateUpdateComment(transition.getTransitionBeanM());
	            
	            if(transitionBean.getLastDateUpdateComment() != null)
	            	this.setLastDateNewComment(transitionBean.getLastUserUpdateComment() + " - "+ FormatFecha.getFormatDate(transitionBean.getLastDateUpdateComment()));
	            
	            
	            if(transitionBean.getLastDateUpdateSubmitFileTransition() != null)
	           	 	this.setLastDateUpdateUploadFileRequeri(transitionBean.getLastUserUpdateSubmitFileTransition() + " - " + transitionBean.getLastDateUpdateSubmitFileTransition());
	           
	            sesion.put("transition",transition);
	            transition.setTransitionBeanM(transitionBean);
//	            this.setClientInfo(transition.getT_clientesDataFromStkBean().getCompanyname() + " - " +transition.getT_clientesDataFromStkBean().getComercialname());
//	        	this.setCorreoIfOwnerInfo(transition.getAsignIfownerStkBean().getIfownwer());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

          /*  try {
				
				transitionBeanM = transitionService.getTransitionBeanIdKnkey(transitionBeanM);
				sesion2.put("Knkey", transitionBeanM);
				transitionBeanM.setTime(new Date());
		        usuarioT.setName(this.getUsuarioT().getUsername());
		        statusselected = transitionBeanM.getStatus();
		        personList = transitionService.getListaNombreDePersonal();
		        
		        
		            //////////////Valida los archivos cargados
		           this.validaArchivosCargados();
		            
		            TransitionBean auxTransitionBean = transitionService.getJoindocumenttransitionDetail(FilesUploadDts.RATE_TRACKER,FilesUploadDts.ACON_DEBTOR_NUMBER, transitionBeanM.getId());
	                transitionBean.setAcondebtornumbertext(auxTransitionBean.getAcondebtornumbertext());
	                transitionBean.setRatetrackertext(auxTransitionBean.getRatetrackertext());

	                //////////////rellena la pantalla transitionLog
	               this.setLog(transitionBeanM,ActionLog.CARGA_TRANSITION,"");
	                
	                

	                /////rellena las pantallas de Client Info e If Owner Info
	                T_clientesDataFromStkBean t_clientesDataFromStkBean = transitionService.getDataFromSTK(transitionBeanM);
	                setClientInfo(t_clientesDataFromStkBean.getCompanyname() + " - " +t_clientesDataFromStkBean.getComercialname());
	                
	                AsignIfownerStkBean asignIfownerStkBean = transitionService.getIfOwnerFromSTK(transitionBeanM);
	                if (asignIfownerStkBean != null) {
	                    setCorreoIfOwnerInfo(asignIfownerStkBean.getIfownwer());
	                }

	                //rellena los checkbox de attachments
	                JoindocumenttransitionBean joindocumenttransitionBean  = transitionService.getVoBoInJoindocumenttransition(transitionBeanM.getId());
	                voBos = joindocumenttransitionBean.getCheckboxesVoBo();
	                box1aux = box1 = voBos.get(0);
	                box2aux = box2 = voBos.get(1);
	                box3aux = box3 = voBos.get(2);
	                box4aux = box4 = voBos.get(3);
	                box5aux = box5 = voBos.get(4);
	                box6aux = box6 = voBos.get(5);
	                box7aux = box7 = voBos.get(6);
	                box8aux = box8 = voBos.get(7);

	   

	                //rellena la tabla dunamica de operations information
	                detallesPersonD = transitionService.getDataPersonalByIdPersonal(transitionBeanM.getId());

			} catch (SQLException e) {
				// TODO Auto-generated catch block
				  
		            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + e.getMessage());
		            return ERROR_SESSION;
			}
           

//        } catch (CstF2Exception ex) {
//            
//            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
//            return ERROR_SESSION;
//        }
*/
        if (this.usuarioT.getUsername().trim().equals("STK")) {
            return "knkeylist";
        } else {
            return SUCCESS;
        }
    }
	
	
	public String saveFilesTxt(){
		try {
			transitionService.updateDetailsInJoindocumenttransition(rateTrackerText, FilesUploadDts.RATE_TRACKER,  transitionBean.getId());
			transitionService.updateDetailsInJoindocumenttransition(acondeborNumberText, FilesUploadDts.ACON_DEBTOR_NUMBER,  transitionBean.getId());
			TransitionBean trans = transitionService.setLastDateUpdateSubmitFileImplementation(transition.getTransitionBeanM(), new Date(), this.getUsuarioT().getUsername());
			this.setLastDateUpdateUploadFileRequeri(trans.getLastUserUpdateSubmitFileTransition() + " - " + FormatFecha.getFormatDate(trans.getLastDateUpdateSubmitFileTransition()));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		


		return SUCCESS;
	}

	
	private boolean validaKnKey(){
		if (transition.getTransitionBeanM().getKnkey() == null) {
            CstF2Exception ex = new CstF2Exception();
            
            addFieldError("Not Knkey Found", "PorFavor Seleccione una Knkey: " + ex.getMessage());
            MainShared mainShared = new MainShared();
            setTransitionBeanArray(mainShared.GetTransitionBeanArrayIdKnkey(this.getUsuarioT()));

            return false;
        }else{
        	return true;
        }
		
	}
	public String insertaComment() {

		String nombre = this.getUsuarioT().getUsername().trim();
		if (sesion.get("nombreSTK") != null && nombre.trim().equals("STK")) {
			nombre = sesion.get("nombreSTK") + " STK";
		}
	
		
		try{
			if(this.newCommnet != null  && !this.newCommnet.equals("")){
				String insert = nombre + " " + new Date() + " " + this.newCommnet
						+ "\n";
				this.insertLog(insert);
				Date date = new Date();
				TransitionBean transitionBean = transitionService.insertLastDateUpdateComment(transition.getTransitionBeanM(),date, this.getUsuarioT().getUsername());
				this.setLastDateNewComment(transitionBean.getLastUserUpdateComment()+ " - "+ FormatFecha.getFormatDate( transitionBean.getLastDateUpdateComment()));
				transitionService.insertHistorico(new HistoricoDto(this.getUsuarioT().getId(), date, "Inserto el comentario: " + this.newCommnet, AccionesHistorico.INSERTA_COMENTARIO));
			}
			
			
		} catch (SQLException e) {

			e.printStackTrace();
		}

		if (this.getUsuarioT().getUsername().equals("STK")) {
			return "knkeylist";
		} else {
			return TRANSITION;
		}
	}
    
   
    public void insertCommentEachAction(String comment) {

        if (transitionBeanM != null) {
            UsuarioDto usuario = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            usuario = (UsuarioDto) sesion.get("usuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            TransitionBean transitionBeanNew = new TransitionBean();
            TransitionShared transitionShared = new TransitionShared();
            TransitionServer transitionServer = new TransitionServer();
            MainServer mainServer = new MainServer();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);

            //guarda el tlog cachado desde el jsp
            transitionBeanNew.setLog(transitionBean.getLog());

            transitionBeanNew.setTime(transitionShared.GetTheDateTime());
            transitionBean = transitionBeanNew;
            transitionBeanM = transitionBeanNew;

            TransitionBean auxTransitionBean;
			try {
				auxTransitionBean = transitionService.getJoindocumenttransitionDetail(FilesUploadDts.RATE_TRACKER,FilesUploadDts.ACON_DEBTOR_NUMBER, transitionBeanM.getId());
				 transitionBean.setAcondebtornumbertext(auxTransitionBean.getAcondebtornumbertext());
		            transitionBean.setRatetrackertext(auxTransitionBean.getRatetrackertext());
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

            String Nombre = usuario.getUsername();
            String Fecha = String.valueOf(transitionBean.getTime());

            String DatosActuales = Nombre.trim() + " " + Fecha + " " + comment + "\n";
            
            //////////////rellena el branch
            try {
				branch = transitionService.branch();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            valBranch = true;
            String msj = transitionServer.getLocality(transitionBeanM.getKnkey());
            if(msj != null)
                msjBranch = transitionServer.validateBranch(transitionBeanM.getKnkey()) + msj;

            //////////////Cambia el status
            mainServer.updatedTrue(transitionBeanM.getKnkey());
            mainServer.updatedTrue1(transitionBeanM.getKnkey());
            
            //////////////Valida los archivos cargados
            if(transitionServer.verifyUploaded("Customer Profile", transitionBeanM.getKnkey())){
                existe1 = true;
            }
            if(transitionServer.verifyUploaded("rfc", transitionBeanM.getKnkey())){
                existe2 = true;
            }
            if(transitionServer.verifyUploaded("R1", transitionBeanM.getKnkey())){
                existe3 = true;
            }
            if(transitionServer.verifyUploaded("R2", transitionBeanM.getKnkey())){
                existe4 = true;
            }
            if(transitionServer.verifyUploaded("Minimum Selling Rates", transitionBeanM.getKnkey())){
                existe5 = true;
            }
            if(transitionServer.verifyUploaded("Sales Quotation", transitionBeanM.getKnkey())){
//                existe6 = true;
            }

            String TlogDB;
//			try {
//				TlogDB = transitionService.getTransitionLog(transitionBeanM.getKnkey());
//				if (TlogDB == null) {
//	                transitionBean.setLog(DatosActuales);
//	                transitionService.updateLogEnTransition(transitionBean);
//	                TlogDB = transitionService.getTransitionLog(transitionBeanM.getKnkey());
//	                setDatos(TlogDB + " \n");
//	            } else {
//	                setDatos(TlogDB + DatosActuales + " \n");
//	                transitionBean.setLog(TlogDB + " " + DatosActuales + "\n");
//	                transitionService.updateLogEnTransition(transitionBean);
//	            }
//			} catch (SQLException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
            
        }
    }

    
  


    public String AgregayValidaNamePersonalM() throws SQLException {
        UsuarioDto usuario = new UsuarioDto();
        //DATOS DEL PERSONAL EXISTENTES EN LA BASE DE DATOS DEL COMBOBOX DEL POP UP
        try {
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            usuario = (UsuarioDto) sesion.get("usuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            statusList.add("On Hold");
            statusList.add("On Going");
            statusList.add("Canceled");
            statusList.add("Closed");
            statusList.add("Completed");

            TransitionShared transitionShared = new TransitionShared("");
            PersonalBean p = new PersonalBean();
            p = transitionService.getDataPersonalByName(person);

            p.setKnkey(transitionBeanM.getKnkey());


            //////////////rellena la pantalla transitionLog
//            String TlogDB = transitionService.getTransitionLog(transitionBeanM.getKnkey());
//            if (TlogDB == null) {
//                transitionBean.setLog("");
//                transitionService.updateLogEnTransition(transitionBean);
//                TlogDB = transitionService.getTransitionLog(transitionBeanM.getKnkey());
//
//                setDatos(usuario.getUsername() + "  " + transitionShared.GetTheDateTime() + "  " + TlogDB);
//            } else {
//                setDatos(TlogDB);
//            }

            /////rellena las pantallas de Client Info e If Owner Info
            setClientInfo(transitionShared.GetDataFromSTK(transitionBeanM).getCompanyname() + " - " + transitionShared.GetDataFromSTK(transitionBeanM).getComercialname());
            AsignIfownerStkBean bean = transitionShared.GetIfOwnerFromSTK(transitionBeanM);
            if (bean != null) {
                setCorreoIfOwnerInfo(bean.getIfownwer());
            }

            personList = transitionService.getListaNombreDePersonal();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBean = transitionBeanNew;

            transitionService.setJoinPersonTransition(p, transitionBean);
            statusselected = transitionShared.GetStatusSelected(transitionBean.getKnkey());

        
    

       

            ////////Agrega en Tlog la accion hecha en este medoto
            insertCommentEachAction("Se Inserto una persona de la base de datos:" + " - " + person);

        } catch (CstF2Exception ex) {
            
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }

        if (usuario.getUsername().trim().equals("STK")) {
            return "knkeylist";
        } else {
            return SUCCESS;
        }
    }

    public String validaNamePersonalMExiste() throws SQLException {
        //DATOS NUEVOS DEL PERSONAL AGREGADOS EN LOS CAMPOS DEL POP UP 
    	

        try {
            TransitionShared transitionShared = new TransitionShared("");
            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanM = transitionBeanNew;

            PersonalBean p = new PersonalBean();
            pb= new PersonalBean();
            pb.setBf(addNewPersonalBF);
            pb.setName(addNewPersonalName);
            pb.setEmail(addNePersonalEmal);
            pb.setPhone(addNewPersonalTelephone);

            p = transitionService.getDataPersonalByEmail(pb.getEmail());
          

            if (p.getId() != null) {
//              El personal ya existe mandar mensaje de existencia
            } else {
                pb.setKnkey(transition.getTransitionBeanM().getKnkey());
                p = transitionService.insertDataPersonal(pb);
        



                transitionService.setJoinPersonTransition(p, transition.getTransitionBeanM());
            }
        } catch (CstF2Exception ex) {
            
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }

        if (this.getUsuarioT().getUsername().trim().equals("STK")) {
            return "knkeylist";
        } else {
            return SUCCESS;
        }
    	
//    	return SUCCESS;
    }

  

    public String generarReportePDF() throws FileNotFoundException, SQLException {
        try {
      
            MyReportCreator myRCPDF = new MyReportCreator();
            pdfInputStream = myRCPDF.generarReporte(transition.getTransitionBeanM().getKnkey());

            insertCommentEachAction("Se descargo el log a un archivo PDF");

            ////////////////rellena nuevamente la lista de usuarios para q no se pierda en el metodo generarreportepdf
            UsuarioDto usuario = new UsuarioDto();
      
            usuario = (UsuarioDto) sesion2.get("usuarioSession");
            TransitionBean transitionBeanNew = new TransitionBean();
            TransitionShared transitionShared = new TransitionShared();
            personList = transitionService.getListaNombreDePersonal();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transition.getTransitionBeanM());
            transitionBean = transitionBeanNew;
            usuarioT.setUsername(usuario.getUsername());
            transitionBean.setTime(transitionBean.getTime());
            transitionShared.GetDocumentName(transitionBean);
            transitionService.getJoindocumenttransitionData(transitionBean);
            String TlogDB = transitionService.getTransitionLog(transition.getTransitionBeanM());

            transitionService.insertHistorico(new HistoricoDto(this.getUsuarioT().getId(), new Date(), "Se descargo el log a un archivo PDF", AccionesHistorico.DESCARGA_LOG_TRANSITION));
        
            //////////////Cambia el status
            this.cambiaEstatus();

            statusselected = transitionShared.GetStatusSelected(transitionBeanM.getKnkey());

            if (TlogDB == null) {
                transitionBean.setLog("");
                transitionService.updateLogEnTransition(transitionBean);
                TlogDB = transitionService.getTransitionLog(transitionBeanM);
                setDatos(usuario.getUsername() + "  " + transitionShared.GetTheDateTime() + "  " + TlogDB);
            } else {
                setDatos(TlogDB);
            }
        } catch (CstF2Exception ex) {
            
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
        }
        return PDF;
    }

    private void uploadFtp(File archivo, String fileType) {
        try {
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            ConexionFtp conexionFtp = new ConexionFtp();
            TransitionServer transitionServer = new TransitionServer();
            InputStream entrada = new FileInputStream(archivo);
            conexionFtp.guarda(transitionBeanM.getKnkey() + ".7z", fileType + "/", entrada);
            
            //////////////Valida los archivos cargados
            if(transitionServer.verifyUploaded("Customer Profile", transitionBeanM.getKnkey())){
                existe1 = true;
            }
            if(transitionServer.verifyUploaded("rfc", transitionBeanM.getKnkey())){
                existe2 = true;
            }
            if(transitionServer.verifyUploaded("R1", transitionBeanM.getKnkey())){
                existe3 = true;
            }
            if(transitionServer.verifyUploaded("R2", transitionBeanM.getKnkey())){
                existe4 = true;
            }
            if(transitionServer.verifyUploaded("Minimum Selling Rates", transitionBeanM.getKnkey())){
                existe5 = true;
            }
            if(transitionServer.verifyUploaded("Sales Quotation", transitionBeanM.getKnkey())){
//                existe6 = true;
            }

        } catch (Exception ex) {
            
            addFieldError("", "Ocurrio un Error: " + ex.getMessage());
        }
    }

 
    public void activeMessage(String file){
            addFieldError("file", "El archivo " + file + " ya ha sido agregado");
    }

    public String executeUpload() throws SQLException {
        statusList.add("On Hold");
        statusList.add("On Going");
        statusList.add("Canceled");
        statusList.add("Closed");
        statusList.add("Completed");

        TransitionShared transitionShared = new TransitionShared();
        TransitionServer transitionServer = new TransitionServer();
        MainServer mainServer = new MainServer();
        UsuarioDto user = new UsuarioDto();
        ActionContext contexto = ActionContext.getContext();
        Map<String, Object> sesion = contexto.getSession();
        user = (UsuarioDto) sesion.get("usuarioSession");
        Map<String, Object> sesion2 = contexto.getSession();
        transitionBeanM = (TransitionBean) sesion2.get("Knkey");
        branch = transitionService.branch();
        valBranch = true;
        String msj = transitionServer.getLocality(transitionBeanM.getKnkey());
        if(msj != null)
            msjBranch = transitionServer.validateBranch(transitionBeanM.getKnkey()) + msj;
        mainServer.updatedTrue(transitionBeanM.getKnkey());
        mainServer.updatedTrue1(transitionBeanM.getKnkey());
        

        transitionShared.updateUploaded("Rate Tracker", transitionBeanM.getKnkey(), transitionBean.getRatetrackertext());
        transitionShared.updateUploaded("ACON Debtor Number", transitionBeanM.getKnkey(), transitionBean.getAcondebtornumbertext());

        ////////////////rellena nuevamente la lista de usuarios para q no se pierda en el metodo generarreportepdf
        UsuarioDto usuario = new UsuarioDto();
        usuario = (UsuarioDto) sesion.get("usuarioSession");
        TransitionBean transitionBeanNew = new TransitionBean();
        transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
        transitionBean = transitionBeanNew;

        personList = transitionService.getListaNombreDePersonal();
        detallesPersonD = transitionService.getDataPersonalByKnkey(transitionBean.getKnkey());

        usuarioT.setUsername(usuario.getUsername());
        transitionBean.setTime(transitionBean.getTime());
        transitionShared.GetDocumentName(transitionBean);
        transitionService.getJoindocumenttransitionData(transitionBean);
        String TlogDB = transitionService.getTransitionLog(transitionBeanM);

        /////rellena las pantallas de Client Info e If Owner Info
        setClientInfo(transitionShared.GetDataFromSTK(transitionBeanM).getCompanyname() + " - " + transitionShared.GetDataFromSTK(transitionBeanM).getComercialname());
        AsignIfownerStkBean bean = transitionShared.GetIfOwnerFromSTK(transitionBeanM);
        if (bean != null) {
            setCorreoIfOwnerInfo(bean.getIfownwer());
        }
        
         //////////////Valida los archivos cargados
        if(transitionServer.verifyUploaded("Customer Profile", transitionBeanM.getKnkey())){
            existe1 = true;
        }
        if(transitionServer.verifyUploaded("rfc", transitionBeanM.getKnkey())){
            existe2 = true;
        }
        if(transitionServer.verifyUploaded("R1", transitionBeanM.getKnkey())){
            existe3 = true;
        }
        if(transitionServer.verifyUploaded("R2", transitionBeanM.getKnkey())){
            existe4 = true;
        }
        if(transitionServer.verifyUploaded("Minimum Selling Rates", transitionBeanM.getKnkey())){
            existe5 = true;
        }
        if(transitionServer.verifyUploaded("Sales Quotation", transitionBeanM.getKnkey())){
//            existe6 = true;
        }

        statusselected = transitionShared.GetStatusSelected(transitionBeanM.getKnkey());
        TransitionBean auxTransitionBean = transitionService.getJoindocumenttransitionDetail(FilesUploadDts.RATE_TRACKER,FilesUploadDts.ACON_DEBTOR_NUMBER, transitionBeanM.getId());
		 transitionBean.setAcondebtornumbertext(auxTransitionBean.getAcondebtornumbertext());
           transitionBean.setRatetrackertext(auxTransitionBean.getRatetrackertext());
	
        if (TlogDB == null) {
            transitionBean.setLog("");
            transitionService.updateLogEnTransition(transitionBean);
            TlogDB = transitionService.getTransitionLog(transitionBeanM);
            setDatos(usuario.getUsername() + "  " + transitionShared.GetTheDateTime() + "  " + TlogDB);
        } else {
            setDatos(TlogDB);
        }

        if (usuario.getUsername().equals("STK                      ")) {
            return "knkeylist";
        } else {
            return SUCCESS;
        }
    }

    private String loadData(TransitionBean transitionBean) {
        UsuarioDto usuario = new UsuarioDto();
        try {

            statusList.add("On Hold");
            statusList.add("On Going");
            statusList.add("Canceled");
            statusList.add("Closed");
            statusList.add("Completed");

            transitionBeanM = new TransitionBean();
            TransitionShared transitionShared = new TransitionShared();

            detallesPersonD = transitionService.getDataPersonalByKnkey(transitionBean.getKnkey());

            personList = transitionService.getListaNombreDePersonal();

            transitionBeanM = transitionShared.GetTransitionBeanIdKnkey(transitionBean);
            transitionBeanM.setTime(transitionShared.GetTheDateTime());

            setClientInfo(transitionShared.GetDataFromSTK(transitionBeanM).getCompanyname() + " - " + transitionShared.GetDataFromSTK(transitionBeanM).getComercialname());
            AsignIfownerStkBean bean = transitionShared.GetIfOwnerFromSTK(transitionBeanM);
            if (bean != null) {
                setCorreoIfOwnerInfo(bean.getIfownwer());
            }

            statusselected = transitionShared.GetStatusSelected(transitionBeanM.getKnkey());

            String TlogDB = transitionService.getTransitionLog(transitionBeanM);
            if (TlogDB == null) {
                transitionBeanM.setLog("");
                transitionService.updateLogEnTransition(transitionBeanM);
                TlogDB = transitionService.getTransitionLog(transitionBeanM);

                setDatos(usuario.getUsername() + "  " + transitionShared.GetTheDateTime() + "  " + TlogDB);
            } else {
                setDatos(TlogDB);
            }

        } catch (Exception ex) {
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }

        if (usuario.getUsername().trim().equals("STK")) {
            return "knkeylist";
        } else {
            return SUCCESS;
        }
    }

    public String downCustomerProfile() {
        return downFile(FilesUploadDts.CUSTOMER_PROFILE);
    }

    public String downRFC() {
        return downFile(FilesUploadDts.RFC);
    }

    public String downR1R2() {
        return downFile(FilesUploadDts.R1_R2);
    }

    public String downSalesCall() {
        return downFile(FilesUploadDts.SALES_CALL);
    }

    public String downCustomerQuotation() {
        return downFile(FilesUploadDts.CUSTOMER_QUOTATION);
    }

 

    public String downFtp7() {
        return downFtp(6);
    }

    public String downFtp8() {
        return downFtp(7);
    }

    private String downFtp(int folder) {

        try {
//        	File file= new File("c:\\adjuntos\\IFE.7z");
            UsuarioDto user = new UsuarioDto();
            TransitionServer transitionServer = new TransitionServer();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            user = (UsuarioDto) sesion.get("usuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");


            String s = getS1();
            String knkey = String.valueOf(transitionBeanM.getKnkey());
            setNombreArchivo(knkey + ".7z");
            String Filename = knkey + ".7z";

            String[] folderArray = s1.split(",");
            //ConexionFtp conexionFtp = new ConexionFtp(folderArray[folder].trim());
            pdfInputStream =new FileInputStream(new File("c:\\adjuntos\\143_IFE.7z"));//conexionFtp.obtenInfo(Filename);

            if (pdfInputStream == null) {
                loadData(transitionBeanM);
                throw new CstF2Exception("No existe el archivo");
            }
            
          /*  ////////Agrega en Tlog la accion hecha en este medoto
            insertCommentEachAction("Se descargo el archivo" + folderArray[folder] + " del ftp");
            
            //////////////Valida los archivos cargados
            if(transitionServer.verifyUploaded("Customer Profile", transitionBeanM.getKnkey())){
                existe1 = true;
            }
            if(transitionServer.verifyUploaded("rfc", transitionBeanM.getKnkey())){
                existe2 = true;
            }
            if(transitionServer.verifyUploaded("R1", transitionBeanM.getKnkey())){
                existe3 = true;
            }
            if(transitionServer.verifyUploaded("R2", transitionBeanM.getKnkey())){
                existe4 = true;
            }
            if(transitionServer.verifyUploaded("Minimum Selling Rates", transitionBeanM.getKnkey())){
                existe5 = true;
            }
            if(transitionServer.verifyUploaded("Sales Quotation", transitionBeanM.getKnkey())){
                existe6 = true;
            }
*/
        } catch (IOException ex) {
//            java.util.logging.Logger.getLogger(TransitionClient.class.getUsername()).log(Level.SEVERE, null, ex);
            addFieldError("Error al obtener el archivo", "Ocurrio un Error: error al descargar archivo. \n" + ex.getMessage());
            return ERROR_DOWN;
        } catch (CstF2Exception ex) {
            
            addFieldError("KnkeyIncorrecta", ex.getMessage());
            return ERROR_DOWN;
        }
        return ZIP;

    }

    
    private String downFile(int file) {
    	
        try {
            String knkey = String.valueOf(transition.getTransitionBeanM().getKnkey());
            setNombreArchivo(knkey + ".7z");
            
            try {
				pdfInputStream =new FileInputStream(new File(FilesUploadDts.RUTA_FILES+"\\"+ transitionService.getJoinDocumentTransaction(file, transition.getTransitionBeanM().getId()).getDetails() ));
				
            } catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}//conexionFtp.obtenInfo(Filename);

            if (pdfInputStream == null) {
                loadData(transitionBeanM);
                throw new CstF2Exception("No existe el archivo");
            }

        } catch (IOException ex) {
//            java.util.logging.Logger.getLogger(TransitionClient.class.getUsername()).log(Level.SEVERE, null, ex);
            addFieldError("Error al obtener el archivo", "Ocurrio un Error: error al descargar archivo. \n" + ex.getMessage());
            return ERROR_DOWN;
        } catch (CstF2Exception ex) {
            
            addFieldError("KnkeyIncorrecta", ex.getMessage());
            return ERROR_DOWN;
        }
        return ZIP;

    }
    
    
    public String insertCheckboxes() throws SQLException {
        String checkboxes = "";
       
        // crea una coleccion
        ArrayList<Boolean> checkbox = new ArrayList<Boolean>();
        // agrega los valores recuperados por el atributo name de los checkboxes del formulario

        JoindocumenttransitionDts joindocumenttransitionBean = new JoindocumenttransitionDts();
        joindocumenttransitionBean.setCheckboxesVoBo(checkbox);

        joindocumenttransitionBean.setIdtransition(transition.getTransitionBeanM().getId());


        //////////////Cambia el status
        
        mainService.updatedTrue1(transition.getTransitionBeanM().getKnkey());

        String cp, rfc, r1r2, salesCall, customerQuotation  , rt,  AconDebtorNumber ;
        
//        Map<Integer,Boolean> checkboxs = transitionService.checkVoBoCheckbox(joindocumenttransitionBean);
        
        
        if(getBox1() == true)
            cp = "Confirmed";
        else
            cp = "Unconfirmed";
        
        checkboxes += "Customer Profile: " + cp + "\n";
        joindocumenttransitionBean.setVobo(getBox1());

        
//        if(checkboxs.get(FilesUploadDts.CUSTOMER_PROFILE) && !getBox1())
//        	transitionService.updateCheckbox(joindocumenttransitionBean, FilesUploadDts.CUSTOMER_PROFILE);


        if(getBox2() == true)
            rfc = "Confirmed";
        else
            rfc = "Unconfirmed";
        
        checkboxes += "RFC: " + rfc + "\n";
        joindocumenttransitionBean.setVobo(getBox2());
//        if(!checkboxs.get(FilesUploadDts.RFC) && getBox2())
//        	transitionService.updateCheckbox(joindocumenttransitionBean, FilesUploadDts.RFC);
       

        if(getBox3() == true)
        	r1r2 = "Confirmed";
        else
        	r1r2 = "Unconfirmed";
        
        checkboxes += "R1_R2: " + r1r2 + "\n";
        joindocumenttransitionBean.setVobo(getBox3());
//        if(! checkboxs.get(FilesUploadDts.R1_R2) && getBox3())
//        	transitionService.updateCheckbox(joindocumenttransitionBean, FilesUploadDts.R1_R2);

        if(getBox4() == true)
        	salesCall = "Confirmed";
        else
        	salesCall = "Unconfirmed";
        
        checkboxes += "SALES CALL: " + salesCall + "\n";
        
        joindocumenttransitionBean.setVobo(getBox4());
//        if(!checkboxs.get(FilesUploadDts.SALES_CALL) && getBox4())
//        	transitionService.updateCheckbox(joindocumenttransitionBean, FilesUploadDts.SALES_CALL);


        if(getBox5() == true)
        	customerQuotation = "Confirmed";
        else
        	customerQuotation = "Unconfirmed";
        
        checkboxes += "Minimun SallingRates: " + customerQuotation + "\n";
        joindocumenttransitionBean.setVobo(getBox5());
//        
//        if(!checkboxs.get(FilesUploadDts.CUSTOMER_QUOTATION) && getBox5())
//        	transitionService.updateCheckbox(joindocumenttransitionBean, FilesUploadDts.CUSTOMER_QUOTATION);

        if(getBox6() == true)
            rt = "Confirmed";
        else
            rt = "Unconfirmed";
        
        checkboxes += "Rate Tracker: " + rt + "\n";
        joindocumenttransitionBean.setVobo(getBox6());

//        if(!checkboxs.get(FilesUploadDts.RATE_TRACKER) && getBox6())
//       	transitionService.updateCheckbox(joindocumenttransitionBean, FilesUploadDts.RATE_TRACKER);

        

        if(getBox7() == true)
        	AconDebtorNumber = "Confirmed";
        else
        	AconDebtorNumber = "Unconfirmed";
        
        checkboxes += "Acon Debtor Number: " + AconDebtorNumber + "\n";
        joindocumenttransitionBean.setVobo(getBox7());

        
        Map<Integer,Boolean> checkboxs = new HashMap<Integer, Boolean>();
        checkboxs.put(FilesUploadDts.CUSTOMER_PROFILE, getBox1());
        checkboxs.put(FilesUploadDts.RFC, getBox2());
        checkboxs.put(FilesUploadDts.R1_R2, getBox3());
        checkboxs.put(FilesUploadDts.SALES_CALL, getBox4());
        checkboxs.put(FilesUploadDts.CUSTOMER_QUOTATION, getBox5());
        checkboxs.put(FilesUploadDts.RATE_TRACKER, getBox6());
        checkboxs.put(FilesUploadDts.ACON_DEBTOR_NUMBER, getBox7());
        
        transitionService.updateJoinTransitionDocuments(checkboxs, transition.getTransitionBeanM().getId());
        
//        if(!checkboxs.get(FilesUploadDts.ACON_DEBTOR_NUMBER) && getBox7())
//        	transitionService.updateCheckbox(joindocumenttransitionBean, FilesUploadDts.ACON_DEBTOR_NUMBER);

        if (!this.getAcondeborNumberText().trim().equals("")) {
            transitionService.updateDetailsInJoindocumenttransition(this.getAcondeborNumberText().trim(), 7, joindocumenttransitionBean.getIdtransition());
        }

        if (!this.getRateTrackerText().trim().equals("")) {
        	transitionService.updateDetailsInJoindocumenttransition(this.getRateTrackerText().trim(), 6, joindocumenttransitionBean.getIdtransition());
        }

        //
                
        
        ////////Agrega en Tlog la accion hecha en este medoto
        
        String comment = "Se actualizaron los Vistos Buenos: \n" + checkboxes;
		String insert = this.getUsuarioT().getUsername() + " " + new Date() + " " + comment + "\n";
		this.insertLog(insert);
		
		
		TransitionBean transitionBean = transitionService.actualizarlastDateUpdateRequeri(transition.getTransitionBeanM().getId(), transition.getTransitionBeanM().getKnkey(), this.getUsuarioT().getUsername());
		
	 this.setLastDateUpdateRequeri(transitionBean.getLastUserUpdateRequeri() + " - " +transitionBean.getLastDateUpdateRequeri());
        
        return SUCCESS;
    }
    
    
    
    public String locality() throws SQLException{
        UsuarioDto usuario = new UsuarioDto();
        try {
            statusList.add("On Hold");
            statusList.add("On Going");
            statusList.add("Canceled");
            statusList.add("Closed");
            statusList.add("Completed");

            if (transitionBeanM != null) {
                ActionContext contexto = ActionContext.getContext();
                Map<String, Object> sesion = contexto.getSession();
                usuario = (UsuarioDto) sesion.get("usuarioSession");
                Map<String, Object> sesion2 = contexto.getSession();
                transitionBeanM = (TransitionBean) sesion2.get("Knkey");

                TransitionBean transitionBeanNew = new TransitionBean();
                TransitionShared transitionShared = new TransitionShared();
                AssignShared assignShared = new AssignShared();
                TransitionServer transitionServer = new TransitionServer();
                MainServer mainServer = new MainServer();
                transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);

                transitionBeanM = transitionBeanNew;   // aki empieza la confusion entre transitionBean y tansitionBeanM el primero con datos del jso y el otro con knkey e id

                usuarioT.setUsername(usuario.getUsername());

                setDatos(usuario.getUsername() + "  " + transitionShared.GetTheDateTime() + "   " + transitionBeanM.getLog());

                personList = transitionService.getListaNombreDePersonal();
                statusselected = transitionShared.GetStatusSelected(transitionBeanM.getKnkey());
                
                MailSender2 mails = new MailSender2();
                TransitionServer ts = new TransitionServer();
                ArrayList<String> correos = new ArrayList<String>();

                correos = ts.confirm(locality);
                System.out.println(correos);

                StringBuilder mensaje = new StringBuilder();
                mensaje.append("Transition iniciated KNKEY: ");
                mensaje.append(transitionBeanM.getKnkey());
                mensaje.append(" COMPANYNAME: ");
                mensaje.append(transitionShared.GetDataFromSTK(transitionBeanM).getCompanyname());

                mails.sendEmail(correos, "Transition", mensaje);

                ts.confirmated(transitionBeanM.getKnkey());
                ts.putLocality(transitionBeanM.getKnkey(), locality);
                mainServer.updatedTrue(transitionBeanM.getKnkey());


                /////rellena las pantallas de Client Info e If Owner Info
                setClientInfo(transitionShared.GetDataFromSTK(transitionBeanM).getCompanyname() + " - " + transitionShared.GetDataFromSTK(transitionBeanM).getComercialname());
                AsignIfownerStkBean bean = transitionShared.GetIfOwnerFromSTK(transitionBeanM);
                if (bean != null) {
                    setCorreoIfOwnerInfo(bean.getIfownwer());
                }

                ////////Agrega en Tlog la accion hecha en este medoto
                insertCommentEachAction("Los usuarios de " + locality + " fueron notificados y asigandos");

                //rellena la tabla dinamica operations information
                detallesPersonD = transitionService.getDataPersonalByIdPersonal(transitionBean.getId());

                //rellena los checkbox de attachments
                JoindocumenttransitionDts joindocumenttransitionBean = new JoindocumenttransitionDts();
                joindocumenttransitionBean = (transitionService.getVoBoInJoindocumenttransition(transitionBean.getId()));
                voBos = joindocumenttransitionBean.getCheckboxesVoBo();
                box1 = voBos.get(0);
                box2 = voBos.get(1);
                box3 = voBos.get(2);
                box4 = voBos.get(3);
                box5 = voBos.get(4);
                box6 = voBos.get(5);
                box7 = voBos.get(6);
                box8 = voBos.get(7);

                //llena los texfields de attachments    
                joindocumenttransitionBean = transitionService.getJoindocumenttransitionData(transitionBean);
                
                //////////////rellena el branch
                branch = transitionService.branch();
                valBranch = true;
                String msj = transitionServer.getLocality(transitionBeanM.getKnkey());
                if(msj != null)
                    msjBranch = transitionServer.validateBranch(transitionBeanM.getKnkey()) + msj;
                
                //////////////Cambia el status
                mainServer.updatedTrue(transitionBeanM.getKnkey());
                mainServer.updatedTrue1(transitionBeanM.getKnkey());
                
                //////////////Valida los archivos cargados
                if(transitionServer.verifyUploaded("Customer Profile", transitionBeanM.getKnkey())){
                    existe1 = true;
                }
                if(transitionServer.verifyUploaded("rfc", transitionBeanM.getKnkey())){
                    existe2 = true;
                }
                if(transitionServer.verifyUploaded("R1", transitionBeanM.getKnkey())){
                    existe3 = true;
                }
                if(transitionServer.verifyUploaded("R2", transitionBeanM.getKnkey())){
                    existe4 = true;
                }
                if(transitionServer.verifyUploaded("Minimum Selling Rates", transitionBeanM.getKnkey())){
                    existe5 = true;
                }
                if(transitionServer.verifyUploaded("Sales Quotation", transitionBeanM.getKnkey())){
//                    existe6 = true;
                }
                
                //////////////Enviar Correo
                ArrayList<Integer> insertKnkeys = new ArrayList<Integer>();
                insertKnkeys.add(transitionBeanM.getKnkey());
                ArrayList<Integer> idTransitions = assignShared.GetIdTransition(insertKnkeys);
                ArrayList<Integer> ids = ts.confirm2(locality);
                for (Integer id : ids){
                    assignShared.InsertRelationUserKnkey(id, idTransitions);
                }
                
                //////////////rellena la pantalla transitionLog
                String TlogDB = transitionService.getTransitionLog(transitionBeanM);
                if (TlogDB == null) {
                    transitionBean.setLog("");
                    transitionService.updateLogEnTransition(transitionBean);
                    TlogDB = transitionService.getTransitionLog(transitionBeanM);

                    setDatos(usuario.getUsername() + "  " + transitionShared.GetTheDateTime() + "  " + TlogDB);
                } else {
                    setDatos(TlogDB);
                }
            } else {
                
                addFieldError("KnkeyIncorrecta", "No hay Knkeys asignadas.");
                return ERROR_SESSION;
            }
        } catch (CstF2Exception ex) {
            
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }

        if (usuario.getUsername().equals("STK                      ")) {
            return "knkeylist";
        } else {
            return SUCCESS;
        }
    }

    public Boolean getValBranch() {
        return valBranch;
    }

    public void setValBranch(Boolean valBranch) {
        this.valBranch = valBranch;
    }

    public String getMsjBranch() {
        return msjBranch;
    }

    public void setMsjBranch(String msjBranch) {
        this.msjBranch = msjBranch;
    }

    public static java.sql.Date convertToSqlDate(java.util.Date oDate) {
        return (new java.sql.Date(oDate.getTime()));
    }
    
    public String getLocality() {
        return locality;
    }

    public void setLocality(String locality) {
        this.locality = locality;
    }
    
    public ArrayList<Localidad> getBranch() {
        return branch;
    }

    public void setBranch(ArrayList<Localidad> branch) {
        this.branch = branch;
    }
    
    public TransitionBean getTransitionBeanM() {
        return transitionBeanM;
    }

    public void setTransitionBeanM(TransitionBean transitionBeanM) {
        this.transitionBeanM = transitionBeanM;
    }

    public Integer getDocumentId() {
        return documentId;
    }

    public void setDocumentId(Integer documentId) {
        this.documentId = documentId;
    }

    public ArrayList<Boolean> getVoBos() {
        return voBos;
    }

    public void setVoBos(ArrayList<Boolean> voBos) {
        this.voBos = voBos;
    }
    private String s1 = "";
    private String nombreArchivo = "";

    public String getNombreArchivo() {
        return nombreArchivo;
    }

    public void setNombreArchivo(String nombreArchivo) {
        this.nombreArchivo = nombreArchivo;
    }

    public Boolean getBox1aux() {
        return box1aux;
    }

    public void setBox1aux(Boolean box1aux) {
        this.box1aux = box1aux;
    }

    public Boolean getBox2aux() {
        return box2aux;
    }

    public void setBox2aux(Boolean box2aux) {
        this.box2aux = box2aux;
    }

    public Boolean getBox3aux() {
        return box3aux;
    }

    public void setBox3aux(Boolean box3aux) {
        this.box3aux = box3aux;
    }

    public Boolean getBox4aux() {
        return box4aux;
    }

    public void setBox4aux(Boolean box4aux) {
        this.box4aux = box4aux;
    }

    public Boolean getBox5aux() {
        return box5aux;
    }

    public void setBox5aux(Boolean box5aux) {
        this.box5aux = box5aux;
    }

    public Boolean getBox6aux() {
        return box6aux;
    }

    public void setBox6aux(Boolean box6aux) {
        this.box6aux = box6aux;
    }

    public Boolean getBox7aux() {
        return box7aux;
    }

    public void setBox7aux(Boolean box7aux) {
        this.box7aux = box7aux;
    }

    public Boolean getBox8aux() {
        return box8aux;
    }

    public void setBox8aux(Boolean box8aux) {
        this.box8aux = box8aux;
    }

    public String getS1() {
        return s1;
    }

    public void setS1(String s1) {
        this.s1 = s1;
    }

    public Boolean getBox1() {
        return box1;
    }

    public void setBox1(Boolean box1) {
        this.box1 = box1;
    }

    public Boolean getBox2() {
        return box2;
    }

    public void setBox2(Boolean box2) {
        this.box2 = box2;
    }

    public Boolean getBox3() {
        return box3;
    }

    public void setBox3(Boolean box3) {
        this.box3 = box3;
    }

    public Boolean getBox4() {
        return box4;
    }

    public void setBox4(Boolean box4) {
        this.box4 = box4;
    }

    public Boolean getBox5() {
        return box5;
    }

    public void setBox5(Boolean box5) {
        this.box5 = box5;
    }

    public Boolean getBox6() {
        return box6;
    }

    public void setBox6(Boolean box6) {
        this.box6 = box6;
    }

    public Boolean getBox7() {
        return box7;
    }

    public void setBox7(Boolean box7) {
        this.box7 = box7;
    }

    public Boolean getBox8() {
        return box8;
    }

    public void setBox8(Boolean box8) {
        this.box8 = box8;
    }


    public String getClientInfo() {
		return clientInfo;
	}

	public void setClientInfo(String clientInfo) {
		this.clientInfo = clientInfo;
	}

	public String getCorreoIfOwnerInfo() {
        return CorreoIfOwnerInfo;
    }

    public void setCorreoIfOwnerInfo(String CorreoIfOwnerInfo) {
        this.CorreoIfOwnerInfo = CorreoIfOwnerInfo;
    }

    public Integer getIdDownloadFtp() {
        return idDownloadFtp;
    }

    public void setIdDownloadFtp(Integer idDownloadFtp) {
        this.idDownloadFtp = idDownloadFtp;
    }

    public ArrayList<PersonalBean> getNewArrayPerson() {
        return newArrayPerson;
    }

    public void setNewArrayPerson(ArrayList<PersonalBean> newArrayPerson) {
        this.newArrayPerson = newArrayPerson;
    }
    private ArrayList<PersonalBean> detallesPersonG = new ArrayList<PersonalBean>();

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public PersonalBean getPb() {
        return pb;
    }

    public void setPb(PersonalBean pb) {
        this.pb = pb;
    }

    public ArrayList<PersonalBean> getDetallesPersonG() {
        return detallesPersonG;
    }

    public void setDetallesPersonG(ArrayList<PersonalBean> detallesPersonG) {
        this.detallesPersonG = detallesPersonG;
    }

    public ArrayList<PersonalBean> getDetallesPersonD() {
        return detallesPersonD;
    }

    public void setDetallesPersonD(ArrayList<PersonalBean> detallesPersonD) {
        this.detallesPersonD = detallesPersonD;
    }

    public String getPerson() {
        return person;
    }

    public void setPerson(String person) {
        this.person = person;
    }

    public ArrayList<String> getPersonList() {
        return personList;
    }

    public void setPersonList(ArrayList<String> personList) {
        this.personList = personList;
    }

    public String getDatos() {
        return datos;
    }

    public void setDatos(String datos) {
        this.datos = datos;
    }

    public UsuarioDto getUsuarioT() {
        return usuarioT;
    }

    public void setUsuarioT(UsuarioDto usuarioT) {
        this.usuarioT = usuarioT;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public TransitionBean getTransitionBean() {
        return transitionBean;
    }

    public void setTransitionBean(TransitionBean transitionBean) {
        this.transitionBean = transitionBean;
    }

    public String getKnkey() {
        return knkey;
    }

    public void setKnkey(String knkey) {
        this.knkey = knkey;
    }

    public ArrayList<String> getStatusList() {
        return statusList;
    }

    public void setStatusList(ArrayList<String> statusList) {
        this.statusList = statusList;
    }

    public InputStream getPdfInputStream() {
        return pdfInputStream;
    }

    public void setPdfInputStream(InputStream pdfInputStream) {
        this.pdfInputStream = pdfInputStream;
    }
    
    
    

    public String getStatusselected() {
        return statusselected;
    }

    public void setStatusselected(String statusselected) {
        this.statusselected = statusselected;
    }
    private ArrayList<TransitionBean> transitionBeanArray;

    public ArrayList<TransitionBean> getTransitionBeanArray() {
        return transitionBeanArray;
    }

    public void setTransitionBeanArray(ArrayList<TransitionBean> transitionBeanArray) {
        this.transitionBeanArray = transitionBeanArray;
    }

    public File getArchivo1() {
        return archivo1;
    }

    public void setArchivo1(File archivo1) {
        this.archivo1 = archivo1;
    }

    public File getArchivo2() {
        return archivo2;
    }

    public void setArchivo2(File archivo2) {
        this.archivo2 = archivo2;
    }

    public File getArchivo3() {
        return archivo3;
    }

    public void setArchivo3(File archivo3) {
        this.archivo3 = archivo3;
    }

    public File getArchivo4() {
        return archivo4;
    }

    public void setArchivo4(File archivo4) {
        this.archivo4 = archivo4;
    }

    public File getArchivo5() {
        return archivo5;
    }

    public void setArchivo5(File archivo5) {
        this.archivo5 = archivo5;
    }

    public File getArchivo6() {
        return archivo6;
    }

    public void setArchivo6(File archivo6) {
        this.archivo6 = archivo6;
    }

    public File getArchivo7() {
        return archivo7;
    }

    public void setArchivo7(File archivo7) {
        this.archivo7 = archivo7;
    }

    public File getArchivo8() {
        return archivo8;
    }

    public void setArchivo8(File archivo8) {
        this.archivo8 = archivo8;
    }

    public Integer getKNKEY() {
        return KNKEY;
    }

    public void setKNKEY(Integer KNKEY) {
        this.KNKEY = KNKEY;
    }

    public Boolean getExiste1() {
        return existe1;
    }

    public void setExiste1(Boolean existe1) {
        this.existe1 = existe1;
    }

    public Boolean getExiste2() {
        return existe2;
    }

    public void setExiste2(Boolean existe2) {
        this.existe2 = existe2;
    }

    public Boolean getExiste3() {
        return existe3;
    }

    public void setExiste3(Boolean existe3) {
        this.existe3 = existe3;
    }

    public Boolean getExiste4() {
        return existe4;
    }

    public void setExiste4(Boolean existe4) {
        this.existe4 = existe4;
    }

    public Boolean getExiste5() {
        return existe5;
    }

    public void setExiste5(Boolean existe5) {
        this.existe5 = existe5;
    }


    
    public Boolean getExiste6() {
		return existe6;
	}

	public void setExiste6(Boolean existe6) {
		this.existe6 = existe6;
	}

	public Boolean getExiste7() {
		return existe7;
	}

	public void setExiste7(Boolean existe7) {
		this.existe7 = existe7;
	}

	public String getLastDateStatusTransition() {
		return lastDateStatusTransition;
	}

	public void setLastDateStatusTransition(String lastDateStatusTransition) {
		this.lastDateStatusTransition = lastDateStatusTransition;
	}

	public String getNewCommnet() {
		return newCommnet;
	}

	public void setNewCommnet(String newCommnet) {
		this.newCommnet = newCommnet;
	}

	public String getLastDateNewComment() {
		return lastDateNewComment;
	}

	public void setLastDateNewComment(String lastDateNewComment) {
		this.lastDateNewComment = lastDateNewComment;
	}

    
    public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
      
    public String cargaInfoTransition(){
    	this.setClientInfo(transition.getT_clientesDataFromStkBean().getCompanyname() + " - " +transition.getT_clientesDataFromStkBean().getComercialname());
    	this.setCorreoIfOwnerInfo(transition.getAsignIfownerStkBean().getIfownwer());
    	return "successFs";
    }
    
    
	public String getStatusTransition() {
		this.setStatusselected(transition.getTransitionBeanM().getStatus());
		statusList = CommonActions.getStatusList(this.statusselected);
		this.getLastUpdateEstatus();
	
		return SUCCESS;
	}
    
    
    public String getOperationsInformation(){
    	this.setDetallesPersonD(transition.getDetallesPersonD());
    	return SUCCESS;
    }
    
    
    public String getRequirements(){

    	this.validaArchivosCargados();
    	JoindocumenttransitionDts joindocumenttransitionBean;
		try {
			joindocumenttransitionBean = transitionService.getVoBoInJoindocumenttransition(transition.getTransitionBeanM().getId());
	        voBos = joindocumenttransitionBean.getCheckboxesVoBo();
	        box1aux = box1 = voBos.get(0);
	        box2aux = box2 = voBos.get(1);
	        box3aux = box3 = voBos.get(2);
	        box4aux = box4 = voBos.get(3);
	        box5aux = box5 = voBos.get(4);
	        box6aux = box6 = voBos.get(5);
	        box7aux = box7 = voBos.get(6);
	       
	        

            TransitionBean auxTransitionBean = transitionService.getJoindocumenttransitionDetail(FilesUploadDts.RATE_TRACKER,FilesUploadDts.ACON_DEBTOR_NUMBER, transition.getTransitionBeanM().getId());
            transitionBean.setAcondebtornumbertext(auxTransitionBean.getAcondebtornumbertext());
            transitionBean.setRatetrackertext(auxTransitionBean.getRatetrackertext());
            
            TransitionBean transitionBean = transitionService.getLastDateUpdateRequi(transition.getTransitionBeanM());
            if(transitionBean.getLastDateUpdateRequeri() != null)
            	this.setLastDateUpdateRequeri(transitionBean.getLastUserUpdateRequeri() + " - " +FormatFecha.getFormatDate(transitionBean.getLastDateUpdateRequeri()));
            
                      
            
            enabledCheckCustomerProfile = enabledCheckRFC = enabledR1R2 = enabledSalesCall = enabledCustomerQuotation = enabledRateTracker = enabledAconDebtorNumber= true;
            
            
            if(!getUsuarioT().getSu()){
            	enabledCheckCustomerProfile = enabledCheckRFC = enabledR1R2 = enabledSalesCall = enabledCustomerQuotation = enabledRateTracker = enabledAconDebtorNumber= false;
            	if(existe1)
        			enabledCheckCustomerProfile = (box1)?false:true;
        		if(existe2)
        			enabledCheckRFC = (box2)?false:true;
        		if(existe3)
        			enabledR1R2 = (box3)?false:true;
        		if(existe4)
        			enabledSalesCall = (box4)?false:true;
        		if(existe5)
        			enabledCustomerQuotation = (box5)?false:true;
        		if(existe6)
        			enabledRateTracker = (box6)?false:true;
        		if(existe7)
        			enabledAconDebtorNumber = (box7)?false:true;
        		
        	
        	}
           
      
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

    	
    	return SUCCESS;
    }
    
    public String geLog(){
    	
    	String TlogDB;
		try {
			TlogDB = transitionService.getTransitionLog(transition.getTransitionBeanM());
			 if (TlogDB == null) {
		            transitionBeanM.setLog("");
		            transitionService.updateLogEnTransition(transitionBeanM);
		            TlogDB = transitionService.getTransitionLog(transitionBeanM);

		            setDatos(this.getUsuarioT().getUsername() + "  " + new Date() + "  " + TlogDB);
		        } else {
		            setDatos(TlogDB);
		        }
		    	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       
    	
    	
    	return SUCCESS;
    }
    
    public String insertStatusTransition(){
    	limpiar();
		if (status.trim().toUpperCase().equals("COMPLETED")) {
			if (box1 && box2 && box3 && box4 && box5 && box6 && box7) {
				
					changestatus();
			
			}else{
//				addFieldError("comboEstatus", "");
				this.setErrorEstatusUpdate(true);
				this.setMsgErrorEstatusUpdate("Check all VoBo");
				this.getLastUpdateEstatus();
				status = statusselected;
				
			}
		} else {
//			if(status.trim().toUpperCase().equals("0")){
//				this.setErrorEstatusUpdate(true);
//				this.setMsgErrorEstatusUpdate("Estatus asignado anteriormente");
//				this.getLastUpdateEstatus();
//				status = statusselected;
//			}else{
//				changestatus();
//			}
		
			if(!status.trim().toUpperCase().equals("0")){
				changestatus();
				this.getLastUpdateEstatus();
				status = statusselected;
				
			}else{
				this.setLastDateStatusTransition(transitionBean.getLastUserUpdateEstatus()+ " - " + FormatFecha.getFormatDate(transitionBean.getLastDateUpdateEstatus()));
				
			}
		}

		if (this.getUsuarioT().getUsername().trim().equals("STK")) {
			return "knkeylist";
		} else {
			return SUCCESS;
		}
    }
    
    private void changestatus(){
    
    	TransitionBean transitionBean;
		try {
			transition.getTransitionBeanM().setStatus(status);
	    	statusselected = status;
			transitionBean = transitionService.updateStatusEnTransition(transition.getTransitionBeanM(),new Date(),this.getUsuarioT().getUsername());
			
			this.setLastDateStatusTransition(transitionBean.getLastUserUpdateEstatus()+ " - " + FormatFecha.getFormatDate(transitionBean.getLastDateUpdateEstatus()));
			
			statusList = CommonActions.getStatusList(this.statusselected);
			mainService.updatedTrue(transition.getTransitionBeanM().getKnkey());
			mainService.updatedTrue1(transition.getTransitionBeanM().getKnkey());
			
			Date fechaAcciones = new Date();
			String comment = "Se Inserto un nuevo status de transition " + this.status;
			String insert = this.getUsuarioT().getUsername() + " " + fechaAcciones+ " " + comment + "\n";
			this.insertLog(insert);
			transitionService.insertHistorico(new HistoricoDto(this.getUsuarioT().getId(), fechaAcciones, comment, AccionesHistorico.CAMBIA_ESTATUS));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
	
    }
    
    public void insertLog(String insert){
    	String TlogDB;
		try {
			TlogDB = transitionService.getTransitionLog(transition.getTransitionBeanM());
			transitionBean.setId(transition.getTransitionBeanM().getId());
			if (TlogDB == null) {
	            transitionBean.setLog(insert);
	            transitionService.updateLogEnTransition(transitionBean);
	            TlogDB = transitionService.getTransitionLog(transitionBeanM);
	            setDatos(TlogDB + " \n");
	        } else {
	            setDatos(TlogDB + insert + " \n");
	            transitionBean.setLog(TlogDB + " " + insert + "\n");
	            transitionService.updateLogEnTransition(transitionBean);
	        }
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
    }
    
    
	public String deletePerson(){
		ActionContext contexto = ActionContext.getContext();
        Map<String, Object> sesion2 = contexto.getSession();
		
		JoinPersonTransitionBean idperson = new JoinPersonTransitionBean();
        idperson.setIdperson(Integer.parseInt(id));
        try {
			transitionService.deleteRelationJoinusertransitionByIdPerson(Integer.parseInt(id), ((TransitionBean)sesion2.get("Knkey")).getId());
			  int veryf = transitionService.verificarCountJoinPersontransition(idperson);
	            if (veryf == 0) {
	                PersonalBean pb = new PersonalBean();
	                pb.setId(Integer.parseInt(id));
	                transitionService.deletePersonalById(pb);
	            } else {
	            
	            }
	        PersonalBean personalBeanEliminado = transitionService.getDataPersonalById(Integer.parseInt(id));
	        String nombreEliminado = personalBeanEliminado.getName();    
	        String comment = "Se Elimino una persona de la base de datos:" + " - " + nombreEliminado;
			String insert = this.getUsuarioT().getUsername() + " " + new Date() + " " + comment + "\n";
			this.insertLog(insert);   
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

        
        if (((UsuarioDto) sesion2.get("usuarioSession")).getUsername().trim().equals("STK")) {
            return "knkeylist";
        } else {
        	result = "OK";
            return SUCCESS;
        }
	}
    
  
	public String addPerson(){
		
		try {
			PersonalBean insertPer = transitionService.getDataPersonalById(Integer.parseInt(idInsertPersonExist));

			transitionService.setJoinPersonTransition(insertPer, transition.getTransitionBeanM());
			
			String comment = "Se Inserto una persona de la base de datos:" + " - " + insertPer.getName();
			String insert = this.getUsuarioT().getUsername() + " " + new Date() + comment + 
					 "\n";
			this.insertLog(insert);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return SUCCESS;
	}
	
	 public String listOptions(){
	    	
	    	try {
				options = transitionService.getPersonalAdd(((TransitionBean)sesion2.get("Knkey"))) ;
				PersonOptions defaultPerson = new PersonOptions();
				defaultPerson.setDisplayText("Select person");
				defaultPerson.setValue("0");
				options.set(0, defaultPerson);
				
		
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		

			
			return SUCCESS;

	    }
	    
    
    private void validaArchivosCargados(){
    	  //////////////Valida los archivos cargados
    	existe1=existe2=existe3=existe4=existe5=existe6=existe7=false;
        FilesUploadDts filesUpload;
		try {
			filesUpload = transitionService.verifyUploaded(transition.getTransitionBeanM());
			   if(filesUpload.isCustomerProfile()){
		            existe1 = true;
		        }
		        if(filesUpload.isRfc()){
		            existe2 = true;
		        }
		        if(filesUpload.isR1_r2()){
		            existe3 = true;
		        }
		        if(filesUpload.isSalesCall()){
		            existe4 = true;
		        }
		        if(filesUpload.isCustomerQuoation()){
		            existe5 = true;
		        }
		        if(filesUpload.isRateTracker())
		        	existe6 = true;
		        if(filesUpload.isAconDebtorNumber())
		        	existe7=true;
		    
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
     
    }

    
   
    
    private void cambiaEstatus(){
    	try {
			mainService.updatedTrue(transition.getTransitionBeanM().getKnkey());
			mainService.updatedTrue1(transition.getTransitionBeanM().getKnkey());
		} catch (SQLException e) {
			e.printStackTrace();
		}
        
    }


    public String notifyStatus(){
    	
    	try {
			mailService.sendNotifyStatusMail(transition.getTransitionBeanM());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return SUCCESS;
    }
    
    
	public String getRateTrackerText() {
		return rateTrackerText;
	}


	public void setRateTrackerText(String rateTrackerText) {
		this.rateTrackerText = rateTrackerText;
	}


	public String getAcondeborNumberText() {
		return acondeborNumberText;
	}


	public void setAcondeborNumberText(String acondeborNumberText) {
		this.acondeborNumberText = acondeborNumberText;
	}


	public String getLastDateUpdateRequeri() {
		return lastDateUpdateRequeri;
	}


	public void setLastDateUpdateRequeri(String lastDateUpdateRequeri) {
		this.lastDateUpdateRequeri = lastDateUpdateRequeri;
	}

	public boolean isErrorEstatusUpdate() {
		return errorEstatusUpdate;
	}

	public void setErrorEstatusUpdate(boolean errorEstatusUpdate) {
		this.errorEstatusUpdate = errorEstatusUpdate;
	}

	public String getMsgErrorEstatusUpdate() {
		return msgErrorEstatusUpdate;
	}

	public void setMsgErrorEstatusUpdate(String msgErrorEstatusUpdate) {
		this.msgErrorEstatusUpdate = msgErrorEstatusUpdate;
	}


	private void limpiar(){
		this.setLastDateStatusTransition("");
		this.setMsgErrorEstatusUpdate("");
		this.setErrorEstatusUpdate(false);
	}
  
    private void getLastUpdateEstatus(){
    	TransitionBean transitionBean;
		try {
			transitionBean = transitionService.getLastDateUpdate(transition.getTransitionBeanM());
			if(transitionBean.getLastDateUpdateEstatus() == null){
				
				this.setLastDateStatusTransition("Unassigned status");
			}else{
				this.setLastDateStatusTransition(transitionBean.getLastUserUpdateEstatus()+ " - " + FormatFecha.getFormatDate(transitionBean.getLastDateUpdateEstatus()));
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    }
    
    
    public String uploadCustom() throws Exception {
		iniciar();

		// aqui se debe verificar el tipo de archivo (ver si se puede hacer por
		// interceptores);

		String guardaName = "";
		File fileToCreate = null;
		if (this.getCustomerProfileFile() != null) {
			//
			guardaName = transitionBean.getId() + "_"
					+ this.getCustomerProfileFileFileName();
			fileToCreate = new File(filePath, guardaName);
			FileUtils.copyFile(this.getCustomerProfileFile(), fileToCreate);
			transitionService.updateUploadedFile(
					FilesUploadDts.CUSTOMER_PROFILE, transitionBean.getId(),
					guardaName);
		
			Date date = new Date();
			String comment = " Se ha cargado  el archivo Customer profile:";
			String insert = this.getUsuarioT().getUsername() + " " + date + comment + 
					 "\n";
			this.insertLog(insert);
			
			TransitionBean trans = transitionService.setLastDateUpdateSubmitFileImplementation(transition.getTransitionBeanM(), date, this.getUsuarioT().getUsername());
			this.setLastDateUpdateUploadFileRequeri(trans.getLastUserUpdateSubmitFileTransition() + " - " + trans.getLastDateUpdateSubmitFileTransition());
		}

		return SUCCESS;

	}

	public String uploadRFC() throws Exception {

		iniciar();

		String guardaName = "";
		File fileToCreate = null;
		if (this.getRfcFile() != null) {
			//
			guardaName = transitionBean.getId() + "_"
					+ this.getRfcFileFileName();
			fileToCreate = new File(filePath, guardaName);
			FileUtils.copyFile(this.getRfcFile(), fileToCreate);
			transitionService.updateUploadedFile(FilesUploadDts.RFC,
					transitionBean.getId(), guardaName);
		}

		return SUCCESS;
	}

	public String uploadR1R2() throws Exception {

		iniciar();

		String guardaName = "";
		File fileToCreate = null;
		if (this.getR1R2File() != null) {
			//
			guardaName = transitionBean.getId() + "_"
					+ this.getR1R2FileFileName();
			fileToCreate = new File(filePath, guardaName);
			FileUtils.copyFile(this.getR1R2File(), fileToCreate);
			transitionService.updateUploadedFile(FilesUploadDts.R1_R2,
					transitionBean.getId(), guardaName);
		}

		return SUCCESS;
	}

	public String uploadSalesCall() throws Exception {

		iniciar();

		String guardaName = "";
		File fileToCreate = null;
		if (this.getSalesCallFile() != null) {
			//
			guardaName = transitionBean.getId() + "_"
					+ this.getSalesCallFileFileName();
			fileToCreate = new File(filePath, guardaName);
			FileUtils.copyFile(this.getSalesCallFile(), fileToCreate);
			transitionService.updateUploadedFile(FilesUploadDts.SALES_CALL,
					transitionBean.getId(), guardaName);
		}

		return SUCCESS;
	}

	public String uploadCustomerQuotation() throws Exception {

		iniciar();

		String guardaName = "";
		File fileToCreate = null;
		if (this.getCustomerQuotationFile() != null) {
			//
			guardaName = transitionBean.getId() + "_"
					+ this.getCustomerQuotationFileFileName();
			fileToCreate = new File(filePath, guardaName);
			FileUtils.copyFile(this.getCustomerQuotationFile(), fileToCreate);
			transitionService.updateUploadedFile(
					FilesUploadDts.CUSTOMER_QUOTATION, transitionBean.getId(),
					guardaName);
		}

		return SUCCESS;
	}

	public String display() {
		return NONE;
	}

	private void iniciar() {
		filePath = FilesUploadDts.RUTA_FILES;

		ActionContext contexto = ActionContext.getContext();
		Map<String, Object> sesion = contexto.getSession();
		transitionBean = (TransitionBean) sesion.get("Knkey");
	}

	

	public String getAuxStatus() {
		return auxStatus;
	}

	public void setAuxStatus(String auxStatus) {
		this.auxStatus = auxStatus;
	}

	public Boolean getEnabledCheckCustomerProfile() {
		return enabledCheckCustomerProfile;
	}

	public void setEnabledCheckCustomerProfile(Boolean enabledCheckCustomerProfile) {
		this.enabledCheckCustomerProfile = enabledCheckCustomerProfile;
	}

	public Boolean getEnabledCheckRFC() {
		return enabledCheckRFC;
	}

	public void setEnabledCheckRFC(Boolean enabledCheckRFC) {
		this.enabledCheckRFC = enabledCheckRFC;
	}

	public Boolean getEnabledR1R2() {
		return enabledR1R2;
	}

	public void setEnabledR1R2(Boolean enabledR1R2) {
		this.enabledR1R2 = enabledR1R2;
	}

	public Boolean getEnabledSalesCall() {
		return enabledSalesCall;
	}

	public void setEnabledSalesCall(Boolean enabledSalesCall) {
		this.enabledSalesCall = enabledSalesCall;
	}

	public Boolean getEnabledCustomerQuotation() {
		return enabledCustomerQuotation;
	}

	public void setEnabledCustomerQuotation(Boolean enabledCustomerQuotation) {
		this.enabledCustomerQuotation = enabledCustomerQuotation;
	}

	public Boolean getEnabledRateTracker() {
		return enabledRateTracker;
	}

	public void setEnabledRateTracker(Boolean enabledRateTracker) {
		this.enabledRateTracker = enabledRateTracker;
	}

	public Boolean getEnabledAconDebtorNumber() {
		return enabledAconDebtorNumber;
	}

	public void setEnabledAconDebtorNumber(Boolean enabledAconDebtorNumber) {
		this.enabledAconDebtorNumber = enabledAconDebtorNumber;
	}

	public String getRateTracker() {
		return transitionBean.getRatetrackertext();
	}

	public void setRateTracker(String rateTracker) {
		this.rateTracker = rateTracker;
	}

	public String getAconDebtorNumber() {
		return  transitionBean.getAcondebtornumbertext();
	}

	public void setAconDebtorNumber(String aconDebtorNumber) {
		this.aconDebtorNumber = aconDebtorNumber;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public PersonalBean getPersonalBean() {
		return personalBean;
	}

	public void setPersonalBean(PersonalBean personalBean) {
		this.personalBean = personalBean;
	}

	public List<PersonOptions> getOptions() {
		return options;
	}

	public void setOptions(List<PersonOptions> options) {
		this.options = options;
	}

	public String getIdInsertPersonExist() {
		return idInsertPersonExist;
	}

	public void setIdInsertPersonExist(String idInsertPersonExist) {
		this.idInsertPersonExist = idInsertPersonExist;
	}


	public File getCustomerProfileFile() {
		return customerProfileFile;
	}


	public void setCustomerProfileFile(File customerProfileFile) {
		this.customerProfileFile = customerProfileFile;
	}


	public File getRfcFile() {
		return rfcFile;
	}


	public void setRfcFile(File rfcFile) {
		this.rfcFile = rfcFile;
	}


	public File getR1R2File() {
		return r1R2File;
	}


	public void setR1R2File(File r1r2File) {
		r1R2File = r1r2File;
	}


	public File getSalesCallFile() {
		return salesCallFile;
	}


	public void setSalesCallFile(File salesCallFile) {
		this.salesCallFile = salesCallFile;
	}


	public File getCustomerQuotationFile() {
		return customerQuotationFile;
	}


	public void setCustomerQuotationFile(File customerQuotationFile) {
		this.customerQuotationFile = customerQuotationFile;
	}


	public String getCustomerProfileFileFileName() {
		return customerProfileFileFileName;
	}


	public void setCustomerProfileFileFileName(String customerProfileFileFileName) {
		this.customerProfileFileFileName = customerProfileFileFileName;
	}


	public String getRfcFileFileName() {
		return rfcFileFileName;
	}


	public void setRfcFileFileName(String rfcFileFileName) {
		this.rfcFileFileName = rfcFileFileName;
	}


	public String getR1R2FileFileName() {
		return r1R2FileFileName;
	}


	public void setR1R2FileFileName(String r1r2FileFileName) {
		r1R2FileFileName = r1r2FileFileName;
	}


	public String getSalesCallFileFileName() {
		return salesCallFileFileName;
	}


	public void setSalesCallFileFileName(String salesCallFileFileName) {
		this.salesCallFileFileName = salesCallFileFileName;
	}


	public String getCustomerQuotationFileFileName() {
		return customerQuotationFileFileName;
	}


	public void setCustomerQuotationFileFileName(
			String customerQuotationFileFileName) {
		this.customerQuotationFileFileName = customerQuotationFileFileName;
	}


	public String getFilePath() {
		return filePath;
	}


	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}


	@Override
	public void setServletRequest(HttpServletRequest request) {
		servletRequest = request;

	}


	public String getLastDateUpdateUploadFileRequeri() {
		return lastDateUpdateUploadFileRequeri;
	}


	public void setLastDateUpdateUploadFileRequeri(
			String lastDateUpdateUploadFileRequeri) {
		this.lastDateUpdateUploadFileRequeri = lastDateUpdateUploadFileRequeri;
	}


	public Boolean getCheckCC() {
		return checkCC;
	}


	public void setCheckCC(Boolean checkCC) {
		this.checkCC = checkCC;
	}


	public String getCustomerProfileFileContentType() {
		return customerProfileFileContentType;
	}


	public void setCustomerProfileFileContentType(
			String customerProfileFileContentType) {
		this.customerProfileFileContentType = customerProfileFileContentType;
	}


	public String getAddNewPersonalBF() {
		return addNewPersonalBF;
	}


	public void setAddNewPersonalBF(String addNewPersonalBF) {
		this.addNewPersonalBF = addNewPersonalBF;
	}


	public String getAddNewPersonalName() {
		return addNewPersonalName;
	}


	public void setAddNewPersonalName(String addNewPersonalName) {
		this.addNewPersonalName = addNewPersonalName;
	}


	public String getAddNePersonalEmal() {
		return addNePersonalEmal;
	}


	public void setAddNePersonalEmal(String addNePersonalEmal) {
		this.addNePersonalEmal = addNePersonalEmal;
	}


	public String getAddNewPersonalTelephone() {
		return addNewPersonalTelephone;
	}


	public void setAddNewPersonalTelephone(String addNewPersonalTelephone) {
		this.addNewPersonalTelephone = addNewPersonalTelephone;
	}
	
	
	
	

}
